package com.example.producer;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 辛之所想
 * @create: 2025-11-01 21:56
 * @description:
 **/
@RestController
public class KafkaProducerController {
    @Autowired
    private KafkaTemplate kafkaTemplate;


    @GetMapping("/send")
    public void send(){
        //http://localhost:8000/send
        kafkaTemplate.send("topic1", "topic1 message");
    }
    @GetMapping("/sendUser")
    public void sendUser(){
        //http://localhost:8000/sendUser
        kafkaTemplate.send("topic_user", JSON.toJSONString(new User("topic_user",1)));
    }

}